package com.kotlin.zds.activity

import android.app.Activity
import android.content.Intent
import android.view.LayoutInflater
import coil.load
import com.alibaba.android.arouter.facade.annotation.Route
import com.kotlin.zds.arouter.Routes
import com.kotlin.zds.base.BaseActivity
import com.kotlin.zds.databinding.ActivityPhotoBinding
import com.kotlin.zds.utils.SelectPhotoUtil
import com.xuexiang.xui.utils.StatusBarUtils
import com.zds.support.util.PopSelectPhotoUtil


/**
 * Author: zds
 * Date: 2022/11/8 14:09
 * Description:
 * Version: v1.0
 */
@Route(path = Routes.PATH_PHOTO)
class PhotoSelectActivity :BaseActivity(){

    var mPath = ""
    var channelId = 0

    val viewBinding by lazy {
        ActivityPhotoBinding.inflate(LayoutInflater.from(mActivity))
    }
    override fun onSetContentView() {
        StatusBarUtils.initStatusBarStyle(this,false)
        setContentView(viewBinding.root)
    }

    override fun initView() {
        viewBinding.run {
            ivPicture.setOnClickListener {
                //SelectPhotoUtil(this@PhotoSelectActivity).select()
                PopSelectPhotoUtil(this@PhotoSelectActivity).select()
            }
        }
    }

    override fun initData() {

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (data != null && resultCode == Activity.RESULT_OK) {
            if (requestCode == SelectPhotoUtil.REQUEST_CODE_PICK_AVATER) {
                val fileUri = data?.data!!
                fileUri.toString()?.let {
                    //viewBinding.ivPicture.loadImageWithoutPlaceholder(it)
                    viewBinding.ivPicture.load(fileUri)
                    mPath = fileUri.path.toString()

                }
            }
        }
    }
}